package com.literaryfamily.literaryfamily.controller;

import com.literaryfamily.literaryfamily.entity.Payments;
import com.literaryfamily.literaryfamily.exceptions.BestException;
import com.literaryfamily.literaryfamily.model.ReturnResult;
import com.literaryfamily.literaryfamily.service.payment.PaymentService;
import com.literaryfamily.literaryfamily.service.user.security.VerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/payment")
public class PaymentController {
	@Autowired
	PaymentService paymentService;
	@Autowired
	VerifyCodeService verifyCodeService;

	//这里是测试用的,其他都没有就暂时先这样
	@GetMapping("/test")
	@ResponseBody
	public ReturnResult<String> payFoOrder() throws BestException {
		ArrayList<String> payments = new ArrayList<>();
		payments.add("pa_1919_08_10_11_45_14_456");
		List<Payments> payments1 = paymentService.selectOrderByTransactionId(payments);
		if (payments1.isEmpty()) {
			return ReturnResult.isFalse("订单不存在");
		}
		System.out.println(payments1);
		return paymentService.placeAnOrder(payments1.get(0), null, 2);
	}

	@GetMapping("/testCode")
	@ResponseBody
	public String testCode() {
		verifyCodeService.sendVerificationCode("18977590817", null, 1);
		return "success";
	}

	@GetMapping("/Code")
	@ResponseBody
	public String testCode(@RequestParam("code") String code) {
		verifyCodeService.validateSmsCode(null, "18977590817", code, 1);
		return "success";
	}
}